#include "stdafx.h"
#include "resource.h"
#include "Game.h"
#include "StateMachine.h"
#include "Elements.h"
#include "DrawWindow.h"
#include "SelectionSystem.h"
#include "FightingSystem.h"

void StateMachine::DrawAsCurrentState(){
	PerformState(CurrentState);
}

void StateMachine::PerformState(GameStates s){
	switch(s){
		case GS_NOSTATE: break;
		case GS_Start:			ItsBeginning(); break;
		case GS_Perface:		ItsPerfaceing();	break;
		case GS_Paused:		ItsPausing();	break;
		case GS_SelectRole:		ItsRoleSelecting();	break;
		case GS_Selection2Fight: ItsSelection2Fight(); break;
		case GS_SelectVenue:	ItsVenueSelecting();	break;
		case GS_Fight:					ItsFighting();	break;
		case GS_Finish:		ItsFinishing();	break;
	}
}

//////////////////////////////////////////////////////////
//state processing function, some actions... showing movie, showing info...
//or, real game...
//or change state

void StateMachine::ItsBeginning(){
	//IntoFighting();
	IntoPerface();
}

void StateMachine::ItsPerfaceing(){
	IntoRoleSelect();
}

void StateMachine::ResumeGame(){
	G.T->Start();
	CurrentState = StateBeforePaused;
}

void StateMachine::PauseGame(){
	StateBeforePaused = CurrentState;
	CurrentState = GS_Paused;
	G.T->Stop();
	//draw a snap
}

void StateMachine::ItsPausing(){
	//drawing the snap
}

void StateMachine::IntoRoleSelect(){
	G.FSS->Reset();
	G.FSS->LoadAll();
	CurrentState = GS_SelectRole;
}

void StateMachine::ItsRoleSelecting(){
	if(G.FSS->PlayerSelected()){
		if(G.FSS->SelectedFighterID[0]==1 && G.FSS->SelectedFighterID[1] ==1){
			G.FSS->UnloadAll(); 
			IntoSelection2Fight();
			return;
		}
	}
	G.FSS->Draw();
	G.MW->Draw();
}

void StateMachine::IntoSelection2Fight(){
	G.CS->LoadAll(G.FSS->SelectedFighterID[0], G.FSS->SelectedFighterID[1]);
	G.FSS->SelectedFighterID[0]=0;
	G.FSS->SelectedFighterID[1]=1;
	CurrentState = GS_Selection2Fight;
}


void StateMachine::ItsSelection2Fight(){
	//an animation change selecting smoothly to fighing ...
	//if(Finished)
	IntoFighting();
}

void StateMachine::ItsVenueSelecting(){

}

void StateMachine::IntoFighting(){
	G.CS->NewCombat();
	CurrentState = GS_Fight;
}

void StateMachine::ItsFighting(){
	G.CS->Draw();
	G.MW->Draw();
}

void StateMachine::ItsFinishing(){
	G.FSS->UnloadAll();
	G.Quit();
}

//////////////////////////////////////////////////////////
//state setting function, some initiating...
//
void StateMachine::BeginGame(){CurrentState = GS_Start;}
void StateMachine::FinishGame(){CurrentState = GS_Finish;}
void StateMachine::IntoPerface( ){CurrentState = GS_Perface;}
void StateMachine::IntoVenueSelect(){CurrentState = GS_SelectVenue;}
